"""将（键-值对组成的）序列转换为（键-列表组成的）字典"""


def group_by(s):
    d = {}
    for k, v in s:
        d.setdefault(k, []).append(v)

    return sorted(d.items())


s = [("yellow", 1), ("blue", 2), ("yellow", 3), ("blue", 4), ("red", 1)]
print(group_by(s))
